<?php

declare(strict_types=1);

namespace App\Model;

/**
 *  视频通话
 */
class VideoCall extends CallBase
{
    protected $table = 'video_call';
    protected $fillable = [
        'user_id', 'chat_user_id', 'status', 'from', 'start_time', 'coin_setting', 'end_time', 'call_mark', 'read'
    ];

    //通话类型
    const CALL_TYPE = 1;

    /**
     * 呼叫页面信息
     */
    static function packCallinfInfo($hostId = 0)
    {
        $profile = UserProfile::getProfile($hostId);
        $posters = UserProfile::getPosters($hostId, $profile, false);
        return [
            'nick_name' => $profile->nick_name,
            'avatar' => $profile->avatar,
            'gender' => $profile->gender,
            'age' => $profile->age,
            'city' => '',
            'level' => 10,
            'close_value' => 10.0,
            'max_close_value' => 100,
            'call_tip' => '',
            'coin_setting' => '',
            'bg_video' => $posters['video'],
            'bg_image' => $posters['photo'] ? $posters['photo'][0] : '',
        ];
    }

    /**
     * 获取当天特惠视频的数量
     * @param $chatUserId
     * @return int
     */
    public static function getDiscountVideTotalDay($chatUserId)
    {
        $where = [
            ['status', '=', CallBase::STATUS_OK],
            ['chat_user_id', '=', $chatUserId],
            ['created_at', '>=', date('Y-m-d 00:00:00')],
            ['created_at', '<=', date('Y-m-d 23:59:59')],
            ['call_mark', '=', 1],
            ['from', '=', CallBase::FROM_DISCOUNT_CALL]
        ];

        return self::where($where)->count();
    }

    /**
     * 获取当天特惠视频的数量
     * @param $chatUserId
     * @return int
     */
    public static function getDiscountVideRank($chatUserId)
    {
        $where = [
            ['status', '=', CallBase::STATUS_OK],
            ['chat_user_id', '=', $chatUserId],
            ['created_at', '>=', date('Y-m-d 00:00:00')],
            ['created_at', '<=', date('Y-m-d 23:59:59')],
            ['call_mark', '=', 1],
            ['from', '=', CallBase::FROM_DISCOUNT_CALL]
        ];

        return self::where($where)->count();
    }

    public static function getInviteVideoTotal($chatUserId)
    {
        $where = [
            ['status', '=', CallBase::STATUS_OK],
            ['chat_user_id', '=', $chatUserId],
            ['from', '=', CallBase::FROM_INVITE_CALL]
        ];

	//暂不可拨打免费电话
	return 1;
        //return self::where($where)->count() ?? 0;
    }
}
